package com.snc.controller.app;


import com.snc.controller.index.BaseController;
import com.snc.entity.TsFormMap;
import com.snc.plugin.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * APP-预约
 */
@Controller
@RequestMapping("/app/ts")
public class TsController extends BaseController{

    /**
     * 获取预约列表集合
     * @param userId 用户ID
     * @return 列表
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/list")
    public Result list(String userId) {
        //构造查询条件
        String where = " createUser = " + userId;

        //根据创建时间倒叙
        where += " order by createTime desc ";

        TsFormMap map = new TsFormMap();
        map.put("where",where);

        List<TsFormMap> data =  map.findByWhere();

        return Result.Success(data);
    }

    /**
     * 创建预约
     * @return 结果
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST,value = "add")
    public Result add() throws Exception {
        TsFormMap apply = super.toFormMap(TsFormMap.class);
        apply.put("createTime",new Date());
        apply.save();
        return Result.Null();
    }

    /**
     * 查询申请消息的详情，请求参数：id
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/info")
    public Result info(){
        TsFormMap map = super.toFormMap(TsFormMap.class);

        map = map.findbyFrist();

        return Result.Success(map);
    }

}